var mongodb = require('mongodb');
//var client = new mongodb.Db('test', new mongodb.Server("127.0.0.1", 27017, {}), {w: 1});
//client.dropDatabase(function(err, done) {
	//client.close();
//});
var client = new mongodb.Db('test', new mongodb.Server("127.0.0.1", 27017, {}), {w: 1});
var test_collection;
var test = function (err, collection) {
	test_collection = collection;
	//*
	collection.find().toArray(function(err, results) {
			//test.assertEquals(1, results.length);
			//test.assertTrue(results[0].a === 2);

			// Let's close the db
			console.log(typeof(results));
			console.log(results);
			client.close();
			console.log('close');
		});
		//*/
	/*
	collection.insert({a:9}, function(err, docs) {

		collection.count(function(err, count) {
			//test.assertEquals(1, count);
			console.log(count);
		});

/*
		// Locate all the entries using find
		collection.find().toArray(function(err, results) {
			//test.assertEquals(1, results.length);
			//test.assertTrue(results[0].a === 2);

			// Let's close the db
			console.log(typeof(results));
			console.log(results);
			client.close();
			console.log('close');
		});
		*/
			//client.close();
	//*/
	//collection.insert({a:9}, function(err, docs) {});
	//client.close();
};

client.open(function(err, p_client) {
	console.log('open');
	//console.log(p_client);
	console.log(typeof(p_client));
	//console.log(JSON.stringify(p_client));
	client.collection('test_insert', test);
	console.log('open end');
	test_collection.insert({a:2}, function(err, docs) {});
	test_collection.insert({a:2}, function(err, docs) {});
	test_collection.insert({a:2}, function(err, docs) {});
	test_collection.insert({a:2}, function(err, docs) {});
	test_collection.insert({a:2}, function(err, docs) {});
	//test_collection = collection;
});

